basepath=$(cd `dirname $0`; pwd)
parentpath=$(dirname $(pwd))
module_name=('admin' 'algorithm' 'api' 'common' 'community' 'default' 'help' 'log' 'manualorder' 'micro' 'realtrade' 'user' 'activity' 'html' 'mystory' 'research' 'third' 'wizardstock' 'factor' 'competition' 'mall')

echo '清理软链'
cd ../ && rm -rf tslint.json tsconfig.json postcss.config.js node_modules

cd tools/

echo '清理软链成功';

echo '创建配置文件'

echo '手动替换config/server.json 和 config/sftp.json 内的name为自己的名称'
echo 'create config/server.json'
cat>./config/server.json<<EOF
{
  "CDN_DOMAIN": "http://name.cdn.kuanke100.com",
  "FILE_DOMAIN": "https://joinquant-file.b0.upaiyun.com",
  "SERVER_DOMAIN": "http://name.dev.kuanke100.com"
}
EOF

echo 'create config/sftp.json'
cat>./config/sftp.json<<EOF
{
  "to": "/home/name/www-std/static/",
  "host": "",
  "username": "name",
  "port": "",
  "privateKey": "/Users/name/.ssh/id_rsa"
}

EOF

echo '创建配置文件完成'

echo '开始创建软连接'

ln -s $basepath'/config/tslint.json' $parentpath'/tslint.json'
ln -s $basepath'/config/tsconfig.json' $parentpath'/tsconfig.json'
ln -s $basepath'/config/postcss.config.js' $parentpath'/postcss.config.js'
ln -s $basepath'/node_modules' $parentpath'/node_modules'
ln -s $basepath'/.babelrc' $parentpath'/.babelrc'

echo $basepath'/config/tslint.json => '$parentpath'/tslint.json'
echo $basepath'/config/tsconfig.json => '$parentpath'/tsconfig.json'
echo $basepath'/config/postcss.config.js => '$parentpath'/postcss.config.js'
echo $basepath'/node_modules => '$parentpath'/node_modules'
echo $basepath'/.babelrc => '$parentpath'/.babelrc'
echo '已将全部node配置软链指向上级'

# if [ ! -d '../modules' ];then
#   mkdir ../modules
# fi
#
# echo '已创建完成module文件夹 准备拉取所有module git代码'
#
# cd ../modules
#
# # 遍历拉取所有module的git
# for i in ${module_name[@]}; do
#
#   if [ ! -d $i ];then
#     echo 'git clone ssh://git@47.93.90.173:23456/www-fe/modules/'$i
#     git clone ssh://git@47.93.90.173:23456/www-fe/modules/$i
#   fi
# done
#
# cd ../
#
# if [ ! -d './common' ];then
#   echo '准备拉取common git代码'
#   echo 'git clone ssh://git@47.93.90.173:23456/www-fe/common'
#   git clone ssh://git@47.93.90.173:23456/www-fe/common
# fi
#
# if [ ! -d './plugin' ];then
#   echo '准备拉取plugin git代码'
#   echo 'git clone ssh://git@47.93.90.173:23456/www-fe/plugin'
#   git clone ssh://git@47.93.90.173:23456/www-fe/plugin
# fi

echo '已完成项目初始化'
